package com.edu.learning.concurrent.custom;

import com.edu.learning.concurrent.custom.queue.IBlockingQueue;

/**
 * 生产者
 *
 * @Author ll
 * @Date 2017/10/16 16:12
 */
public class Producer implements Runnable {

    private IBlockingQueue<String> queue;
    private int consumer;

    public Producer(IBlockingQueue<String> queue, int consumer) {
        this.queue = queue;
        this.consumer = consumer;
    }

    @Override

    public void run() {
        for (int i = 0; i < 100; i++) {
            try {
                queue.put("data_" + i);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

        for (int i = 0; i < consumer; i++) {
            try {
                queue.put("FIN");
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        System.out.println("Producer over");
    }
}
